<?php

namespace app\admin\controller\workorder;

use app\common\model\Config;
use app\common\controller\Backend;

/**
 * 工单字段管理
 */
class Fields extends Backend
{

    /**
     * Fields模型对象
     * @var \app\admin\model\workorder\Fields
     */
    protected $model       = null;
    protected $noNeedRight = ['rulelist'];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\workorder\Fields();
        $this->view->assign("positionList", $this->model->getPositionList());
        $this->view->assign("typeListList", $this->model->getTypeListList());
        $this->view->assign("statusList", $this->model->getStatusList());
        $this->view->assign("isbasicinfoList", $this->model->getIsbasicinfoList());
        $this->view->assign('autofillList', $this->model->getAutofillList());
    }

    public function import()
    {
        parent::import();
    }

    /**
     * 规则列表
     * @internal
     */
    public function rulelist()
    {
        //主键
        $primaryKey = $this->request->request("keyField");

        //主键值
        $keyValue = $this->request->request("keyValue", "");

        $keyValueArr = array_filter(explode(',', $keyValue));
        $regexList   = Config::getRegexList();
        $list        = [];
        foreach ($regexList as $k => $v) {
            if ($keyValueArr) {
                if (in_array($k, $keyValueArr)) {
                    $list[] = [$primaryKey => $k, 'name' => $v];
                }
            } else {
                $list[] = [$primaryKey => $k, 'name' => $v];
            }
        }
        return json(['list' => $list]);
    }

}
